# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dm.dm_collect_analysis_detail import jms_dm__dm_collect_analysis_detail
from jms.dwd.tab.dwd_tab_barscan_deliver_base_dt import jms_dwd__dwd_tab_barscan_deliver_base_dt
from jms.dwd.tab.dwd_tab_barscan_sitearrival_base_dt import jms_dwd__dwd_tab_barscan_sitearrival_base_dt
from jms.dwd.tab.dwd_tab_barscan_sign_base_dt import jms_dwd__dwd_tab_barscan_sign_base_dt
from jms.dwd.tab.dwd_tab_barscan_collect_base_dt import jms_dwd__dwd_tab_barscan_collect_base_dt
from jms.dwd.tab.dwd_tab_barscan_centersend_base_dt import jms_dwd__dwd_tab_barscan_centersend_base_dt
from jms.dwd.tab.dwd_tab_barscan_send_base_dt import jms_dwd__dwd_tab_barscan_send_base_dt
from jms.dwd.tab.dwd_tab_barscan_sitesend_base_dt import jms_dwd__dwd_tab_barscan_sitesend_base_dt
from jms.dwd.tab.dwd_tab_barscan_arrival_base_dt import jms_dwd__dwd_tab_barscan_arrival_base_dt
from jms.dwd.tab.dwd_tab_reback_transfer_express_base import jms_dwd__dwd_tab_reback_transfer_express_base
# 集散待散货
jms_dm__dm_collect_ready_send_detail = SparkSqlOperator(
    task_id='dm__dm_collect_ready_send_detail',
    pool_slots=1,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='dm__dm_collect_ready_send_detail_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_collect_ready_send_detail/execute.hql',
    driver_memory='4G',
    driver_cores=4,
    executor_memory='12G',
    executor_cores=8,
    num_executors=30,
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    conf={'spark.executor.memoryOverhead': 4096,
          'spark.core.connection.ack.wait.timeout': 5000,
          'spark.default.parallelism': 600,
          'spark.locality.wait': 60,
          'spark.driver.maxResultSize': 4, #限制driver计算结果大小，超出报OutOfMemoryError
          'spark.sql.shuffle.partitions': 600,
          'spark.dynamicAllocation.maxExecutors': 32,  # 动态资源最大扩容 Executor 数
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2',
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
                  'hive.exec.dynamic.partition.mode': 'nonstrict',
                  'hive.exec.max.dynamic.partitions.pernode': 200,
                  'hive.exec.max.dynamic.partitions': 200
                  },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=120),
)

jms_dm__dm_collect_ready_send_detail << [
    jms_dim__dim_network_whole_massage,
    jms_dm__dm_collect_analysis_detail,
    jms_dwd__dwd_tab_barscan_sign_base_dt,
    jms_dwd__dwd_tab_barscan_collect_base_dt,
    jms_dwd__dwd_tab_barscan_centersend_base_dt,
    jms_dwd__dwd_tab_barscan_send_base_dt,
    jms_dwd__dwd_tab_barscan_sitesend_base_dt,
    jms_dwd__dwd_tab_barscan_arrival_base_dt,
    jms_dwd__dwd_tab_barscan_deliver_base_dt,
    jms_dwd__dwd_tab_barscan_sitearrival_base_dt,
    jms_dwd__dwd_tab_reback_transfer_express_base
]
